import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/ui/draw_under_line.dart';
import 'package:meal/ui/pay_pwd.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 确认账号转账
///
class TransferConfirm extends StatefulWidget {
  const TransferConfirm({Key? key}) : super(key: key);

  @override
  State<TransferConfirm> createState() => _TransferConfirmState();
}

class _TransferConfirmState extends State<TransferConfirm> {
  String money = '', remark = '', pwd = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('确认账号转账',
          actions: ToolsUtils.actions('转账记录', pressed: () {
            Get.toNamed(RouteGet.financeTransferRecord);
          })),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(Sizes.default20),
        child: Column(
          children: [
            Stack(
              children: [
                Container(
                  height: 180,
                  decoration: BoxDecoration(
                      color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
                  padding: const EdgeInsets.symmetric(vertical: Sizes.default20),
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.center,
                        child: ToolsUtils.getUrlSvg(
                            'https://cdn7.axureshop.com/demo/1525603/images/余额转账/u2051.svg',
                            width: Sizes.default80,
                            height: Sizes.default80),
                      ),
                      Container(
                        margin: const EdgeInsets.only(top: Sizes.default15, bottom: Sizes.default8),
                        alignment: Alignment.center,
                        child: Text(
                          'Honor1',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default16, color: ColorsUtils.color363),
                        ),
                      ),
                      Center(
                        child: Text(
                          '1357898901',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.color797),
                        ),
                      )
                    ],
                  ),
                ),
                Positioned(
                    top: 0,
                    right: 0,
                    child: IconButton(
                        onPressed: () {
                          Get.back();
                        },
                        icon: Icon(
                          AntdIcons.edit,
                          size: Sizes.default20,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.color999),
                        )))
              ],
            ),
            Container(
              margin: const EdgeInsets.only(top: Sizes.default20),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
              padding: const EdgeInsets.all(Sizes.default10),
              child: ListBody(
                children: [
                  Container(
                    height: Sizes.default40,
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '转账金额',
                      style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color333, fontSize: Sizes.default15),
                    ),
                  ),
                  SizedBox(
                      height: Sizes.default50,
                      child: DrawUnderLine(
                        color: ColorsUtils.parseColorFromHexString('#D7D7D7'),
                        dx: Sizes.default10,
                        child: Row(
                          children: [
                            Text(
                              '￥',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color515, fontSize: Sizes.default28),
                            ),
                            Expanded(
                                child: Container(
                              padding: const EdgeInsets.symmetric(horizontal: Sizes.default5),
                              child: TextField(
                                style: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color000, fontSize: Sizes.default18),
                                decoration: InputDecoration(
                                    border: const OutlineInputBorder(
                                      borderSide: BorderSide.none,
                                    ),
                                    isCollapsed: true,
                                    filled: true,
                                    fillColor: Colors.transparent,
                                    contentPadding: const EdgeInsets.symmetric(
                                        horizontal: Sizes.default10, vertical: Sizes.default10),
                                    constraints: const BoxConstraints(minHeight: Sizes.default40),
                                    hintText: '请输入金额',
                                    hintStyle: StylesUtils.customTextStyle(
                                        fontSize: Sizes.default18, color: ColorsUtils.color000)),
                                keyboardType: TextInputType.number,
                                onChanged: (String content) {
                                  setState(() {
                                    money = content;
                                  });
                                },
                              ),
                            )),
                          ],
                        ),
                      )),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default5),
                    child: TextField(
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color000),
                      decoration: InputDecoration(
                          border: const OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                          isCollapsed: true,
                          filled: true,
                          fillColor: Colors.transparent,
                          contentPadding: const EdgeInsets.symmetric(
                              horizontal: Sizes.default10, vertical: Sizes.default10),
                          constraints: const BoxConstraints(minHeight: Sizes.default40),
                          hintText: '添加备注 (限50字)',
                          hintStyle: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                      keyboardType: TextInputType.text,
                      onChanged: (String content) {
                        setState(() {
                          remark = content;
                        });
                      },
                    ),
                  )
                ],
              ),
            ),
            Container(
              height: Sizes.default40,
              alignment: Alignment.centerLeft,
              margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text(
                '账户余额：￥5021.25',
                style: StylesUtils.customTextStyle(color: ColorsUtils.color797),
              ),
            ),
            SizedBox(
              height: Sizes.default50,
              child: FractionallySizedBox(
                heightFactor: 0.9,
                widthFactor: 1.0,
                child: GFButton(
                    onPressed: onSubmit,
                    text: '确认转账',
                    textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                    shape: GFButtonShape.pills,
                    type: GFButtonType.solid,
                    color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
              ),
            )
          ],
        ),
      ),
    );
  }

  void onSubmit() {
    showDialog(
        context: context,
        barrierDismissible: true,
        builder: (_) {
          return StatefulBuilder(builder: (BuildContext context, setState) {
            return PayPwd(
                pwd: pwd,
                callback: (String value) {
                  setState(() {
                    if (value.length == 6) {
                      /// 跳转
                      Future.delayed(const Duration(milliseconds: 50), () {
                        Navigator.of(context).pop();
                        pwd = '';
                        Get.toNamed(RouteGet.financeTransferResult);
                      });
                    } else {
                      pwd = value;
                    }
                  });
                });
          });
        });
  }
}
